<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <j-form-container>
        <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
          <a-row>
            <a-col :span="24">
              <a-form-model-item label="槽号" :labelCol="labelCol" :wrapperCol="wrapperCol">
               {{model.slotName}}
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type">
                <a-select v-model="model.type" defaultValue="新极" style="width: 100px" prop="type">
                  <a-select-option value="新极">新极</a-select-option>
                  <a-select-option value="残极">残极</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="使用天数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="timeLimit">
                <a-input-number v-model="model.timeLimit" placeholder="请输入使用天数" style="width: 100px" />
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="位置" :labelCol="labelCol" :wrapperCol="wrapperCol">
                {{model.position }}
              </a-form-model-item>
            </a-col> 
            <a-col :span="24">
              <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
                <a-textarea v-model="model.remark" rows="4" placeholder="请输入备注" />
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </j-form-container>
    </a-spin>
  </j-modal>
</template>

<script>
  import { httpAction, getAction } from '@/api/manage' 
    import JCheckbox from '@/components/jeecg/JCheckbox'
  export default {
    name: 'AnodeChangeMiniForm',
    components: {
       JCheckbox,
    },
    data () {
      return {
        title:'',
        width:800,
        visible: false,
        disableSubmit: false,
         model:{
          timeLimit:35,
          type:'新极',
         },
        positionA:[],
        positionB:[],
        positionList:[],
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           slotName: [
              { required: true, message: '请输入槽号!'},
           ],
           type: [
              { required: true, message: '请输入类型!'},
           ],
           timeLimit: [
              { required: true, message: '请输入使用天数!'},
           ],
           position: [
              { required: true, message: '请输入位置!'},
           ],
        },
        url: {
          add: "/anodeChange/anodeChange/add",
          edit: "/anodeChange/anodeChange/edit",
          queryById: "/anodeChange/anodeChange/queryById"
        },  
      } 
    },
    methods: { 
      edit (record) {
        this.visible=true
        this.$nextTick(()=>{
          this.model = Object.assign({}, record);
          this.model.id = '';
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        this.submitForm();
      },
      submitCallback(){
        this.$emit('ok');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      },
       submitForm () {
        const that = this;
    
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) { 
            that.confirmLoading = true; 
            that.save( this.url.add,'post');
          } 
        })
      },
      save(httpurl,method){
        const that = this; 
         httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){ 
                that.confirmLoading = false;
                that.$message.success(res.message);
                that.$emit('ok');
                that.visible = false;
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
          
            })
      },
    }
  }
</script>